package com.mob.tools.log;

import android.content.Context;
import com.mob.tools.MobLog;
import com.mob.tools.utils.R;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class NativeErrorHandler
{
  private static final int MAX_LOG_SIZE = 100;
  private static final boolean enable;

  static
  {
    try
    {
      System.loadLibrary("neh");
      bool = true;
      enable = bool;
      return;
    }
    catch (Throwable localThrowable)
    {
      while (true)
        boolean bool = false;
    }
  }

  private static String getCachePath(Context paramContext)
  {
    File localFile = new File(R.getCacheRoot(paramContext), "NativeCrashLogs");
    if (!localFile.exists())
      localFile.mkdirs();
    return localFile.getAbsolutePath();
  }

  private static native void nativePrepare(String paramString);

  private static ArrayList<NativeCrashInfo> parseIndex(String paramString)
    throws Throwable
  {
    File localFile = new File(paramString, ".ncl");
    if (!localFile.exists())
      return new ArrayList();
    BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(localFile)));
    ArrayList localArrayList = new ArrayList();
    String str = localBufferedReader.readLine();
    while (str != null)
    {
      String[] arrayOfString = str.split(",");
      if (arrayOfString.length >= 2)
      {
        NativeCrashInfo localNativeCrashInfo = new NativeCrashInfo(null);
        localNativeCrashInfo.time = R.parseLong(arrayOfString[0]);
        localNativeCrashInfo.signal = R.parseInt(arrayOfString[1]);
        localArrayList.add(localNativeCrashInfo);
        str = localBufferedReader.readLine();
      }
    }
    localBufferedReader.close();
    return localArrayList;
  }

  private static String parseLog(String paramString, NativeCrashInfo paramNativeCrashInfo)
    throws Throwable
  {
    File localFile = new File(paramString, "." + paramNativeCrashInfo.time);
    if (!localFile.exists())
      return "";
    BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(localFile)));
    LinkedList localLinkedList = new LinkedList();
    for (String str = localBufferedReader.readLine(); str != null; str = localBufferedReader.readLine())
    {
      localLinkedList.add(str);
      if (localLinkedList.size() > 100)
        localLinkedList.remove(0);
    }
    localBufferedReader.close();
    StringBuffer localStringBuffer = new StringBuffer();
    Iterator localIterator = localLinkedList.iterator();
    while (localIterator.hasNext())
      localStringBuffer.append((String)localIterator.next()).append('\n');
    if (localStringBuffer.length() > 0)
      return localStringBuffer.substring(0, -1 + localStringBuffer.length());
    return "";
  }

  public static boolean prepare(Context paramContext)
  {
    if (enable)
    {
      String str = getCachePath(paramContext);
      uploadCreashLog(str);
      nativePrepare(str);
    }
    return enable;
  }

  private static void uploadCreashLog(String paramString)
  {
    try
    {
      Iterator localIterator = parseIndex(paramString).iterator();
      while (localIterator.hasNext())
      {
        String str = parseLog(paramString, (NativeCrashInfo)localIterator.next());
        MobLog.getInstance().nativeCrashLog(str);
      }
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
      return;
    }
    R.deleteFileAndFolder(new File(paramString));
  }

  private static class NativeCrashInfo
  {
    public int signal;
    public long time;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.log.NativeErrorHandler
 * JD-Core Version:    0.6.2
 */